package cn.yunhe.controller;

import cn.yunhe.pojo.ModuleP;
import cn.yunhe.pojo.PageBean;
import cn.yunhe.service.ModuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("module")
public class ModuleController {


    @Autowired
    private ModuleService moduleService;

    @RequestMapping("list")
    public String listDeptAndParent(Model model, PageBean pageBean) {
        PageBean pb = moduleService.listDeptOfPage(pageBean);
        pb.setUrl("/module/list");
        model.addAttribute("pb", pb);
        System.out.println(pb.getDatas().get(1));
        return "sysadmin/module/jModuleList";
    }

    @RequestMapping("toview")
    public String toview(String id, Model model) {
        ModuleP moduleP = moduleService.findById(id);
        model.addAttribute("module", moduleP);
        return "sysadmin/module/jModuleView";
    }

    @RequestMapping("tocreate")
    public String tocreate(Model model) {
        List<ModuleP> modulePS=moduleService.findAll();
        model.addAttribute("ms", modulePS);
        return "sysadmin/module/jModuleCreate";
    }
    @RequestMapping("toupdate")
    public String toupdate(String id,Model model){

        ModuleP moduleP = moduleService.findById(id);
        model.addAttribute("module", moduleP);
        return "sysadmin/module/jModuleUpdate";
    }
}
